package com.hex.liyue.usermodule.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.activity.BaseActivity;
import com.hex.liyue.commonmodule.utils.L;
import com.hex.liyue.commonmodule.utils.StatusBarCompatUtils;
import com.hex.liyue.commonmodule.view.recycleview.YRecycleview;
import com.hex.liyue.giftmodule.adapter.AdapterGiveGifts;
import com.hex.liyue.giftmodule.bean.GiveGiftsBean;
import com.hex.liyue.lookingdatemodule.bean.AppointmentDetailsResultBean;
import com.hex.liyue.lookingdatemodule.presenter.IInSomeDetailsView;
import com.hex.liyue.lookingdatemodule.presenter.InSomeDetailsPresenter;
import com.hex.liyue.usermodule.adapter.AdapterVideoLists;
import com.hex.liyue.usermodule.bean.VideoListsBean;
import com.hex.liyue.usermodule.presenter.IVideoListsView;
import com.hex.liyue.usermodule.presenter.VideoListsPresenter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by $cmm on 2016/7/9.
 * 个人中心获取所有小视频列表的界面
 */
public class VideoListActivity extends BaseActivity implements IVideoListsView {
    @Bind(R.id.iv_toobar_back)
    ImageView ivToobarBack;
    @Bind(R.id.tv_toobar_title)
    TextView tvToobarTitle;
    @Bind(R.id.rv_harvest_gifts)
    YRecycleview rvHarvestGifts;
    @Bind(R.id.empty_gift)
    LinearLayout emptyGift;

    private IVideoListsView iVideoListsView;
    private int page = 1, page_num = 10;
    private List<VideoListsBean.DataBean> list = new ArrayList<>();
    private AdapterVideoLists adapterVideoLists;
    private VideoListsPresenter videoListsPresenter;

    @Override
    protected void bindPresenter() {
        videoListsPresenter = new VideoListsPresenter(this);
    }

    @Override
    protected void initData(Bundle extras) {
        videoListsPresenter.getVideoLists();
        rvHarvestGifts.setReFreshEnabled(false);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_my_videos;
    }

    @Override
    protected void initToolbar() {
        StatusBarCompatUtils.compat(this);
        tvToobarTitle.setText("我的视频");
        ivToobarBack.setVisibility(View.VISIBLE);
    }


    @OnClick({R.id.iv_toobar_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_toobar_back:
                onBackPressed();
                break;
        }
    }


    @Override
    public void setAdapter(final VideoListsBean videoListsBean) {
        if (videoListsBean.data.size() > 0) {


            if (adapterVideoLists == null) {
                for (VideoListsBean.DataBean dataBean : videoListsBean.data) {
                    list.add(dataBean);
                }
                adapterVideoLists = new AdapterVideoLists();
//
                rvHarvestGifts.setLayoutManager(new LinearLayoutManager(this));
                rvHarvestGifts.setAdapter(adapterVideoLists);
                rvHarvestGifts.setEmptyView(emptyGift);
                rvHarvestGifts.setLoadMoreEnabled(false);//禁用加载
                rvHarvestGifts.setReFreshEnabled(false);//禁用刷新;
                adapterVideoLists.setList(list);
            }
            adapterVideoLists.setContext(this);
            adapterVideoLists.notifyDataSetChanged();
            rvHarvestGifts.reSetStatus();
        }else{
            rvHarvestGifts.setVisibility(View.GONE);
        }
//        L.d("WJ", page + "=size=" + giveGiftsBean.data.size());
    }

    @Override
    public void showLod(String msg) {
        showLoad(VideoListActivity.this, msg);
    }

    @Override
    public void closeLod() {
        closeLoad();
    }

    @Override
    public void showT(String msg) {
        showToast(VideoListActivity.this, msg);
    }


}
